package com.dxysun.design.observer.universe;

import java.util.ArrayList;
import java.util.List;

public class ConcreteSubject<E> implements ISubject<E>
{
	private List<IObserver<E>> observerList = new ArrayList<>();

	@Override
	public boolean attach(IObserver<E> iObserver)
	{
		return observerList.add(iObserver);
	}

	@Override
	public boolean detach(IObserver<E> iObserver)
	{
		return observerList.remove(iObserver);
	}

	@Override
	public void notify(E e)
	{
		observerList.forEach(o -> o.update(e));
	}
}
